package edu.westga.sketchit2009cs.network;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class PlayerClient {
	
	private Socket playerSocket;
	private ObjectInputStream input;

	public PlayerClient(String hostIP, String portNumber) {
		
		int thePortNumber = Integer.parseInt(portNumber);
		try {
			this.playerSocket = new Socket(hostIP, thePortNumber);
		} catch (Exception e) {

		} 
		try {
			executeClient();
		} catch (Exception e) {

		}
		
	}

	private void executeClient() throws UnknownHostException, IOException{	
		this.input = new ObjectInputStream(
							this.playerSocket.getInputStream());
		
		try {
			String inputFromServer = (String) this.input.readObject();
			System.out.println(inputFromServer);
			
			while (!inputFromServer.trim().equalsIgnoreCase("bye")) {				
				inputFromServer = (String) this.input.readObject();
				System.out.println(inputFromServer);
			}
		} 
		catch (ClassNotFoundException e) {

		}
		this.input.close();
		this.playerSocket.close();
	}
}
